﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command.SheepChangeDormCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.SheepChangeDormHandler
{
	public class ChangeDormAddHandler : IRequestHandler<ChangeDormAddCommand, Results<int>>
	{
		/// <summary>
		/// Service
		/// </summary>

		private readonly IChangeDormitoryService service;
		/// <summary>
		/// AutoMapper
		/// </summary>
		private readonly IMapper mapper;

		public ChangeDormAddHandler(IChangeDormitoryService service, IMapper mapper)
		{
			this.service = service;
			this.mapper = mapper;
		}

		/// <summary>
		/// 羊只添加
		/// </summary>
		/// <param name="request"></param>
		/// <param name="cancellationToken"></param>
		/// <returns></returns>
		/// <exception cref="NotImplementedException"></exception>

		public async Task<Results<int>> Handle(ChangeDormAddCommand request, CancellationToken cancellationToken)
		{
			//	throw new NotImplementedException();
			var changemodel=  mapper.Map<List<SheepChangeDormitory>>(request.changeDormitoriesList);

			var res =await service.AddChangeDormitory(changemodel);

	    	return  Results<int>.DataResult(res);

		}
	}
}
